import React from 'react';
import ReactDOM from 'react-dom';

import {
    HashRouter as Router,
    Route,
    Switch,
    Redirect
} from 'react-router-dom'

import {
    Provider
} from 'mobx-react';

import {
    Tools,
    Toast,
    Bubble
} from 'weaver-mobile';
import loadjs from 'loadjs'
import allStore from './stores';

import {
    asyncComponent
} from 'react-async-component';

import './style';

window.gaodeMapWebKey = 'a2b37e22742652fd5f87c6a4f8a01301';
const coms = {
    Home: asyncComponent({
        resolve: () =>
            import ("./components/Home")
    }),
    Sign: asyncComponent({
        resolve: () =>
            import ("./components/sign/index")
    }),
    MapSign: asyncComponent({
        resolve: () =>
            import ("./components/mapSign/index")
    }),
    OutSign: asyncComponent({
        resolve: () =>
            import ("./components/outSign/index")
    }),
    SignV2: asyncComponent({
        resolve: () =>
            import ("./components/signV2/index")
    }),
    MapSignV2: asyncComponent({
        resolve: () =>
            import ("./components/mapSignV2/index")
    }),
    OutSignV2: asyncComponent({
        resolve: () =>
            import ("./components/outSignV2/index")
    }),
    QRLogin: asyncComponent({
        resolve: () =>
            import ("./components/login/QR/index")
    }),
    QRCACheck: asyncComponent({
        resolve: () =>
            import ("./components/login/QR/QRCACheck.js")
    }),
    AddressBook: asyncComponent({
        resolve: () =>
            import ("./components/addressBook/index")
    }),
    ResourceInfo: asyncComponent({
        resolve: () =>
            import ("./components/resource/index")
    }),
    Subordinate: asyncComponent({
        resolve: () =>
            import ("./components/resource/Subordinate")
    }),
    ChangePassword: asyncComponent({
        resolve: () =>
            import ("./components/password/changePassword/index")
    }),
    ForgetPassword: asyncComponent({
        resolve: () =>
            import ("./components/password/forgetPassword/index")
    }),
    TestCaButton: asyncComponent({
        resolve: () =>
            import ('./components/login/QR/test/testCaButton')
    }),
    TestQRLoginCa: asyncComponent({
        resolve: () =>
            import ('./components/login/QR/test/testQrLoginCa')
    }),
    SecondaryVerification: asyncComponent({
        resolve: () =>
            import ("./components/password/secondaryVerification/index")
    }),
    PasswordSetting: asyncComponent({
        resolve: () =>
            import ("./components/password/passwordSetting/index")
    }),
    PersonalInfo: asyncComponent({
        resolve: () =>
            import ("./components/personalInfo/index")
    }),
    AccountSetting: asyncComponent({
        resolve: () =>
            import ("./components/accountSetting/index")
    }),
    PayrollDetail: asyncComponent({
        resolve: () =>
            import ("./components/payrollDetail/index")
    }),
    MyAttendance: asyncComponent({
        resolve: () =>
            import ("./components/myAttendance/index")
    }),
    SubAttendance: asyncComponent({
        resolve: () =>
            import ("./components/myAttendance/my/MyAttendance")
    }),
    MyAttendanceCopy: asyncComponent({
        resolve: () =>
            import ("./components/myAttendanceCopy/index")
    }),
    SubAttendanceCopy: asyncComponent({
        resolve: () =>
            import ("./components/myAttendanceCopy/my/MyAttendance")
    }),
    VacationBalance: asyncComponent({
        resolve: () =>
            import ("./components/vacationBalance/index")
    }),
    Test: asyncComponent({
        resolve: () =>
            import ("./components/test/index")
    }),
    Group: asyncComponent({
        resolve: () =>
            import ("./components/group/index")
    }),
    OperateGroup: asyncComponent({
        resolve: () =>
            import ("./components/group/OperateGroup")
    }),
    SuggestDetail: asyncComponent({
        resolve: () =>
            import ("./components/group/SuggestDetail")
    }),
    GroupAdvice: asyncComponent({
        resolve: () =>
            import ("./components/groupAdvice/index")
    }),
    SecretGuard: asyncComponent({
        resolve: () =>
            import ("./components/secretGuard/index")
    }),
    HappyBirthday: asyncComponent({
        resolve: () =>
            import ("./components/happyBirthday/index")
    }),
    SendBless: asyncComponent({
        resolve: () =>
            import ("./components/sendBless/index")
    }),
    BlessCard: asyncComponent({
        resolve: () =>
            import ("./components/blessCard/index")
    })
}

class Root extends React.Component {
    // constructor(props){
    //     super(props);
    //     this.init();
    // }

    // init = () => {
    //     loadjs.isDefined('qing') ? loadjs.ready('qing') : loadjs('https://static.yunzhijia.com/public/js/qing/latest/qing.js', 'qing', this.rewriteEM);
    // }

    // rewriteEM = () => {
    //     window.em = {
    //         checkJsApi: func => ['getLocation'].indexOf(func) > -1,
    //         ready: callback => callback && callback(),
    //         getLocation: params => {
    //             params.success({
    //                     address: '中国上海市闵行区联航路召楼路',
    //                     longitude: 121.52646,
    //                     latitude: 31.08013,
    //                     status: '1'
    //                 })
    //             // window.qing.call('getLocation', {
    //             //     success: result => {
    //             //         const {success, error, errorCode, data} = result;
    //             //         if(!!success || success == 'true'){
    //             //             const {latitude, longitude, address, addressdetail} = data;
    //             //             params.success && params.success({latitude, longitude, address: addressdetail || address});
    //             //         }else{
    //             //             params.fail && params.fail({success, error, errorCode});
    //             //         }
    //             //     }
    //             // });
    //         }
    //     }
    // }

    render() {
        return (
            <Provider {...allStore}>
                <Router>
                    <Route name="home" path="/" render={() => {
                        return (
                            <coms.Home>
                                <Route name="testQrLoginCa" path='/testQrLoginCa' component={coms.TestQRLoginCa} />
                                <Route name="testCaButton" path='/testCaButton' component={coms.TestCaButton} />
                                <Route name="qrLogin" path="/qrLogin" component={coms.QRLogin} />
                                <Route name="qrCACheck" path="/qrCACheck" component={coms.QRCACheck} />
                                <Route name="sign" path="/signal" component={coms.Sign} />
                                <Route name="mapSign" path="/mapSign" component={coms.MapSign} />
                                <Route name="outSign" path="/outSign" component={coms.OutSign} />
                                <Route name="sign" path="/signalV2" component={coms.SignV2} />
                                <Route name="mapSign" path="/mapSignV2" component={coms.MapSignV2} />
                                <Route name="outSign" path="/outSignV2" component={coms.OutSignV2} />
                                <Route name="addressBook" path="/addressBook" component={coms.AddressBook} />
                                <Route name="resourceInfo" path="/resourceInfo/:id" component={coms.ResourceInfo} />
                                <Route name="subordinate" path="/subordinate/:id" component={coms.Subordinate} />
                                <Route name="changePassword" path="/changePassword" component={coms.ChangePassword} />
                                <Route name="forgetPassword" path="/forgetPassword" component={coms.ForgetPassword} />
                                <Route name="secondaryVerification" path="/secondaryVerification" component={coms.SecondaryVerification} />
                                <Route name="passwordSetting" path="/passwordSetting" component={coms.PasswordSetting} />
                                <Route name="personalInfo" path="/personalInfo" component={coms.PersonalInfo} />
                                <Route name="accountSetting" path="/accountSetting" component={coms.AccountSetting} />
                                <Route name="payrollDetail" path="/payrollDetail/:id" component={coms.PayrollDetail} />
                                <Route name="myAttendance" path="/myAttendance" component={coms.MyAttendance} />
                                <Route name="subAttendance" path="/subAttendance/:id" component={coms.SubAttendance} />
                                <Route name="myAttendanceCopy" path="/sign" component={coms.MyAttendanceCopy} />
                                <Route name="subAttendanceCopy" path="/subAttendanceCopy/:id" component={coms.SubAttendanceCopy} />
                                <Route name="vacationBalance" path="/vacationBalance" component={coms.VacationBalance} />
                                <Route name="test" path="/test" component={coms.Test} />
                                <Route name="group" path="/group" component={coms.Group} />
                                <Route name="operateGroup" path="/groupOp" component={coms.OperateGroup} />
                                <Route name="suggestDetail" path="/suggestDetail" component={coms.SuggestDetail} />
                                <Route name="groupAdvice" path="/groupAdvice" component={coms.GroupAdvice} />
                                <Route name="secretGuard" path="/secretGuard" component={coms.SecretGuard} />
                                <Route name="happyBirthday" path="/birthdayRemind/:id" component={coms.HappyBirthday} />
                                <Route name="sendBless" path="/sendBless" component={coms.SendBless} />
                                <Route name="blessCard" path="/blessing/:id" component={coms.BlessCard} />
                                <Route name="attendanceInfo" path="/attendanceInfo" component={coms.MyAttendanceCopy} />
                            </coms.Home>
                        )
                    }} />
                </Router>
            </Provider>
        )
    }
}

// Tools.getLocaleLabel("hrm", () => { // 多语言
//     ReactDOM.render(<Root />, document.getElementById('root'));
// });

if(window.isLocalApp && window.localAppUa === 'EM7') {
    window.getLocalInfo().then(()=>Tools.getLocaleLabel("hrm", () => { // 多语言
        ReactDOM.render(<Root />, document.getElementById('root'));
    }));
  } else {
    Tools.getLocaleLabel("hrm", () => { // 多语言
        ReactDOM.render(<Root />, document.getElementById('root'));
    });
  }
